package pers.qianyu.month_202101.date_20210110;

/**
 * 260. 只出现一次的数字 III
 * https://leetcode-cn.com/problems/single-number-iii/
 *
 * @author mizzle rain
 * @date 2021-01-10 12:27
 */
public class SingleNumberThree {
    public int[] singleNumber(int[] nums) {
        int s = 0;
        for (int num : nums) s ^= num;
        int k = 0;
        while (((s >> k) & 1) == 0) k++;
        int s1 = 0;
        for (int num : nums) {
            if (((num >> k) & 1) == 1) {
                s1 ^= num;
            }
        }
        return new int[]{s1, s ^ s1};
    }
}
